Field of the Invention
The present invention relates to test cases for software testing, and more specifically, to a method and apparatus for providing test cases.
Brief Description of Related Art
In the process of software development, developers write source codes of programs for functions to be implemented by software, and then testers use test cases to test software built based on source codes. It can be understood that a program usually constructs a plurality of flow branches by using, for example, condition judgment and jump statement, so as to form a plurality of execution paths. Therefore, it is desired to select appropriate test cases to constitute a test suite so that respective test cases in the test suite can correspond to different flow branches, cover different execution paths, and thus test various possible execution conditions of the program comprehensively. To this end, in the prior art, a method of symbolic execution has been proposed to analyze the execution process of a program. This method can be used to generate appropriate test cases for a program.
In the method of symbolic execution, Control Flow Graph, CFG, is constructed for a program to be tested. CFG is an abstract data structure using a directional graph to represent a program process. FIG. 1 exemplarily shows a program's control flow graph and corresponding execution paths thereof. Specifically, FIG. 1 contains a plurality of nodes and a plurality of directed edges connecting the nodes, wherein each node Ni represents a program basic block, that is, a sequential statement code block having no jump therein, and each directed edge Ei represents a jump in the program and connects two basic blocks (i.e., nodes) that act as the start point and end point of the jump respectively. Since a jump in a program is usually defined through an execution condition, a directed edge corresponds to an execution condition of jumping from the start node to the end node of the directed edge. For example, in a specific example, a plurality of variables including x and y are defined in a program. After executing node N1, the program judges values of variables x and y. If (x+y)>=0, then it jumps to node N2; if (x+y)<0 and y>0, then it jumps to node N3. Then, directed edge E1 corresponds to the execution condition (x+y)>=0; and directed edge E2 corresponds to the execution condition (x+y)<0 and y>0. By connecting different nodes via different directed edges, different execution paths can be formed. Specifically, FIG. 1 further shows different combinations of directed edges corresponding to different execution paths; for example, the execution path p1 executes a series of nodes N1, N2, N6, N5, Nf via directed edges E0, E1, E3, E7 and E9. As mentioned before, each directed edge corresponds to an execution condition of jumping from the start node to the end node of the directed edge. Therefore, each execution path pi can correspond to an execution condition set, or called a constraint set, defined by a combination of directed edges. If the constraint set has no solution, it means the execution path pi is not reachable. For a reachable path, by solving the constraint set, a condition range for the program to execute the path pi can be obtained. Further, a test case ti can be generated within the condition range. In this way, respective parameters in the test case ti are in compliance with the condition range of the path pi, and then, when using the test case ti for test, the program will certainly conduct the execution along the path pi, and thus the test on the path pi is implemented. That is to say, the test case ti is a test case applicable for the execution path pi. In the same way, different test cases can be generated for respective different execution paths of the program. Then, the different test cases generated can cover different execution paths to meet the requirements of comprehensive testing.
However, in order to meet various needs of users for software functions, many programs have complex logics and a large number of process branches. It can be understood that each time there is a process branch increased, new execution paths will be generated through combination on the basis of the original execution paths. Therefore, the number of execution paths grows exponentially as the number of branches increases. A large number of process branches can generate a huge number of execution paths, and this is also called path state space explosion. For such cases, the method of generating test cases for respective execution paths by solving the constraint sets thereof one by one becomes unpractical because of low efficiency.
On the other hand, the development of software program is finished step by step. Developers (usually a number of developers for large software) continue to submit modification tracks to the program source code, so as to modify, supplement and improve the source code. In order to assure that a software program modified several times can run normally, it is needed to perform regression testing on the software program to determine which modification track causes problems for the program. According to the prior art, in the process of regression testing, the same test suite is used to test different versions of the program. However, in practice, each modification to the program is likely to cause a change in execution paths of the program. Therefore, it is possible that a test case applicable for a specific execution path in the original version of the program can no longer be applicable for the modified program, while on the contrary, an applicable test case could not be found for a new execution path generated due to a program change. Therefore, it is desired to update the test suite for the modified program, to provide applicable test cases. However, as mentioned before, on one hand, logics of programs are more and more complex, and the number of execution paths is huge; on the other hand, programs are modified very frequently. These two factors make regenerating test cases for each modification of the program very costly.
Therefore, it is desired to propose a new solution, which can provide an applicable test case for a modification of the program more effectively.